#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
typedef struct _stValue
{
  int   m_nID;
  char  m_szName[20];
  bool  m_bSex;
}TStu;
int main(int argc, char* argv[])
{
  /**assign
   */
  TStu t1;
  memset(&t1, 0x00, sizeof(TStu));
  t1.m_nID = 0;
  snprintf(t1.m_szName, 20, "%s", "hellow");
  t1.m_bSex = true;
  string a;
  a.assign((char*)&t1, sizeof(TStu));

  char buf[100] = {0};
  memcpy(buf, a.c_str(), a.size());
  TStu *pt2 = (TStu*)buf;
  printf("ID = [%d]\nName = [%s]\nSex=[%02x]\n", pt2->m_nID, pt2->m_szName, pt2->m_bSex);
  /**
   * size,length,capacity,max_size
   */
  cout <<a <<endl;
  printf("stirng strlen c_str()= [%d]\n", strlen(a.c_str()));
  printf("stirng size = [%d]\n", a.size());
  printf("stirng length = [%d]\n", a.length());
  printf("stirng capacity = [%d]\n", a.capacity());
  printf("stirng max_size = [%d]\n", a.max_size());
  /**append
   */
  string s1;
  char test1[] = "hellow";
  s1.append(test1, 3);
  cout << s1 << endl;
  char test2[] = "abcdefghijklmn";
  s1.append(test2, 10);
  cout << s1 << endl;
  s1.clear();
  s1.append(test2, 10);
  cout << s1 << endl;
  /**insert
   */
  string s2("I you");
  s2.insert(1, " love");
  cout << s2 << endl;
  return 0;
}
